package net.oschina.arvin.multi.field.sort;

import java.util.Map;

/**
 * Map 结构
 *
 * @author Arvin
 * @time 2017/9/30 23:20
 */
public class MapSortItem extends AbstractSortItem {

    /** key名称 */
    private String key;

    public MapSortItem(String key, boolean asc) {
        this.key = key;
        this.asc = asc;
    }

    public String getKey() {
        return key;
    }

    @Override
    public int compare(Object o1, Object o2) {
        try {
            Object v1 = ((Map) o1).get(this.key);
            Object v2 = ((Map) o2).get(this.key);
            return compareValue(v1, v2);
        } catch (Exception e) {
            return 0;
        }
    }

}
